#include <iostream>

using namespace std;

const int N = 1000;
long long t19 = 524288, t20 = 1048576;
long long g[N][N], f[2][N][N];
long long s[N];
long long ans = (long long)100000000 * 100000000;
long long t = 0;

long long nextT() {
    t = ((long long) 615949 * t + 797807) % t20;
    return t - t19;
}

int main() 
{
    cout << ans << endl;
    // init the triangle;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i + 1; j++) {
            g[i][j] = nextT();
        }
    }

    for (int i = 0; i < N; i++) {
        int c = i & 1, p = !(i & 1); // current and previous
        s[0] = g[i][0];
        for (int j = 0; j < i + 1; j++) {
            f[c][j][j] = g[i][j];
            if (j > 0) {
                s[j] = g[i][j] + s[j-1];
            }
        }

        for (int j = 0; j < i; j++) {
            for (int k = j + 1; k < i + 1; k++) {
                long long sjk = s[k];
                if (j > 0) sjk -= s[j-1];
                f[c][j][k] = sjk + f[p][j][k-1];
                if (ans > f[c][j][k]) {
                    ans = f[c][j][k];
                    cout << i << ' ' << j << ' ' << k << ' ' << ans << endl;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}
